﻿@page "/login1"
@layout EmptyLayout
@inherits LoginPage

<div class="login">
    <div class="login-head">
        <div class="login-logo">
            <a class="kui-logo" href="@Config.SiteUrl" target="_blank"></a>
            <div class="kui-app-name">@Language["App.SubTitle"]</div>
        </div>
        <ul class="kui-menu">
            <li><a href="@Config.SiteUrl/doc" target="_blank">@Language["Document"]</a></li>
            @if (Config.App.IsLanguage)
            {
                <li style="text-align:center;"><NavLanguage /></li>
            }
            @if (Config.App.IsTheme)
            {
                <li style="margin-left:15px;"><NavTheme /></li>
            }
        </ul>
    </div>
    <div class="login-body">
        <div class="login-left">
            <ul>
                <li>@Language["OpenSource"]</li>
                <li>@Language["LowCode"]</li>
                <li>@Language["ModernUI"]</li>
            </ul>
            <img src="img/login.png" />
        </div>
        <div class="login-form">
            <div class="login-form-body">
                <Tabs Class="kui-login" Animated>
                    <TabPane Key="Account" Tab="@Language?["Login.WithAccount"]">
                        <LoginForm Model="Model" OnLogin="OnUserLogin" IsCaptcha="IsCaptcha" />
                    </TabPane>
                    <TabPane Key="QRCode" Tab="@Language?["Login.WithQRCode"]">
                        <div style="text-align:center;">
                            <div style="margin-bottom:10px;">请使用手机浏览器扫码登录</div>
                            <KQRCode Option="QrCode" />
                        </div>
                    </TabPane>
                </Tabs>
            </div>
        </div>
    </div>
    <div class="login-copyright"><KFooter /></div>
</div>

@code {
    private bool IsCaptcha => Config.System?.IsLoginCaptcha == true;
    private object QrCode => new { Text = Config.HostUrl, Width = 200, Height = 200 };

    [CascadingParameter] private HttpContext HttpContext { get; set; }
    [Inject] private IAuthStateProvider AuthProvider { get; set; }

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();
        if (HttpMethods.IsGet(HttpContext.Request.Method))
        {
            await AuthProvider.SignOutAsync();
            Model.UserName = "Admin";
            Model.Password = "888888";
        }
    }

    protected override async Task OnLoginedAsync(UserInfo user)
    {
        await base.OnLoginedAsync(user);
        var url = Context.IsMobileApp ? "/app" : (ReturnUrl ?? "/");
        HttpContext.Response.Redirect(url);
    }
}